package com.android.danaobank.adapter;

import android.os.Build;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.android.danaobank.BuildConfig;
import com.android.danaobank.R;
import com.android.danaobank.model.response.Advertisement;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.youth.banner.adapter.BannerAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.util.BannerUtils;

import java.util.List;

public class BannerAdAdapter extends BannerAdapter<Advertisement, BannerImageHolder> {
    public BannerAdAdapter(List<Advertisement> datas) {
        super(datas);
    }

    @Override
    public BannerImageHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = (ImageView) BannerUtils.getView(parent, R.layout.banner_image);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            BannerUtils.setBannerRound(imageView, 8);
        }
        return new BannerImageHolder(imageView);
    }

    @Override
    public void onBindView(BannerImageHolder holder, Advertisement data, int position, int size) {
        Glide.with(holder.itemView)
                .load(BuildConfig.IMAGE_BASE + data.getImg())
//                .thumbnail(Glide.with(holder.itemView)
//                        .load(R.drawable.loading))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(8)))
                .into(holder.imageView);
    }
}
